package com.example.mybaiduweishi.activity;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.widget.FrameLayout;

import com.example.mybaiduweishi.R;
import com.example.mybaiduweishi.activity.base.BaseActivity;
import com.example.mybaiduweishi.fragments.firstFragment;
import com.example.mybaiduweishi.fragments.secondFragment;

import butterknife.BindView;

public class OneKeySOSActivity extends BaseActivity {
    firstFragment first;

    @BindView(R.id.layout_onekey_help_toolbar)
    Toolbar layoutOnekeyHelpToolbar;
    @BindView(R.id.fl_sos)
    FrameLayout flSos;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        layoutOnekeyHelpToolbar.setTitle("一键求救");
        setSupportActionBar(layoutOnekeyHelpToolbar);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public int getContentXML() {
        return R.layout.activity_one_key_sos;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
        //加载Fragment
        if (first == null){
            first = new firstFragment();
        }
       getFragmentManager().beginTransaction().replace(R.id.fl_sos,first).addToBackStack("SOS").commit();

    }

    public void toSecondFragment(){
        getFragmentManager().beginTransaction().hide(first).add(R.id.fl_sos,new secondFragment()).addToBackStack("SOS").commit();
    }
    public void onBackPressed(){
        if (getSupportFragmentManager().getBackStackEntryCount() > 1){
            getSupportFragmentManager().popBackStack();
        }else {
            finish();
        }
    }
}
